package ifpb.monteiro.p2.projetoFinal;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class BroadcastServer {

	@SuppressWarnings("resource")
	public static void main(String[] args) throws Exception {

		DatagramSocket datagramaConexao = new DatagramSocket();
		datagramaConexao.setBroadcast(true);

		byte[] b = new byte[100];

		DatagramPacket pacote = new DatagramPacket(b, b.length);
		pacote.setAddress(InetAddress.getByAddress(new byte[] { (byte) 255,
				(byte) 255, (byte) 255, (byte) 255 }));

		pacote.setPort(5000);

		int i = 0;

		while (true) {

			String s = new Integer(i++).toString();
			b = s.getBytes();
			pacote.setData(b);

			datagramaConexao.send(pacote);

			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		// ServerSocket server = new ServerSocket(5000);
		// DatagramSocket datagrama = new DatagramSocket(5000);
		// byte[] mascara = "255.255.255.255";
		// DatagramPacket pacote = new DatagramPacket(buf, length, address,
		// port)
//		while (true) {
//			Socket socket = Socket.accept();
//			System.out.println(socket);
//		}
	}
}
// }
